package com.xunfang.controller;

import com.xunfang.bean.Building;
import com.xunfang.bean.dto.BuildQueryDTO;
import com.xunfang.common.Result;
import com.xunfang.service.IBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2023 -11-02
 * @desc
 */
@RestController
@RequestMapping("building")
public class BuildingController {

    @Autowired
    private IBuildingService buildingService;

    @PostMapping("list/{currentPage}/{pageSize}")
    public Result findBuildService(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody BuildQueryDTO buildQueryDTO){
        return Result.ok(buildingService.findBuilds(currentPage,pageSize,buildQueryDTO));
    }

    @DeleteMapping("{id}")
    public Result deleteBuildById(@PathVariable Integer id){
        return Result.ok(buildingService.removeBuildById(id) ? "操作成功":"操作失败或者数据有引用...不能删除");
    }

    @PutMapping()
    public Result updateBuildById(@RequestBody Building building){
        return Result.ok(buildingService.updateBuildById(building) ? "操作成功":"操作失败");
    }

    @PostMapping()
    public Result addBuildById(@RequestBody Building building){
        return Result.ok(buildingService.addBuildById(building) ? "操作成功":"操作失败");
    }

    //批量删除
    @DeleteMapping()
    public Result deleteBuildByIds(@RequestBody List<Integer> ids){
        return Result.ok(buildingService.batchBuild(ids) ? "操作成功":"操作失败");
    }

    //查询所欲
    @GetMapping("list")
    public Result findBuildListService(){
        return Result.ok(buildingService.findBuildsAll());
    }
}
